﻿using System.Collections;
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;

public class AssetLabelsEditor : AssetPostprocessor {

    static void OnPostprocessAllAssets(string[] importedAssets, string[] deletedAssets, string[] movedAssets, string[] movedFromAssetPaths)
    {
        // string[] extList = new[] {".png", ".jpg", ".tga"};
        // foreach (var item in importedAssets) {
        //     if (item.IndexOf(".") == -1) {
        //         // 文件夹
        //         continue;
        //     }
        //     if (item.IndexOf(EditorConfig.MODEL_PATH) != -1) {
        //         // 打包Model文件夹下的模型或者贴图或者prefab
        //         string basePath = item.Substring(item.IndexOf(EditorConfig.MODEL_PATH)   EditorConfig.MODEL_PATH.Length);
        //         basePath = basePath.Substring(0, basePath.IndexOf("/"));
        //         string ext = Path.GetExtension(item);
        //         if (EditorConfig.EXPORT_MODEL_DIRECTLY.Contains(basePath)) {
        //             if (extList.Contains(ext) || ext == ".fbx") {
        //                 // 此文件夹下只导出贴图和模型
        //                 string relativePath = item.Substring(item.IndexOf(EditorConfig.PATH_TAG)   EditorConfig.PATH_TAG.Length);
        //                 string prefabName = relativePath.Substring(0, relativePath.IndexOf('.'))   EditorConfig.ASSETBUNDLE_EXT;
        //                 SetAssetBundleName(item, prefabName.ToLower());
        //             } else {
        //                 SetAssetBundleName(item, null);
        //             }
        //         } else {
        //             if (extList.Contains(ext) || ext == ".prefab") {
        //                 // 此文件夹下只导出贴图和prefab
        //                 string relativePath = item.Substring(item.IndexOf(EditorConfig.PATH_TAG)   EditorConfig.PATH_TAG.Length);
        //                 string prefabName = relativePath.Substring(0, relativePath.IndexOf('.'))   EditorConfig.ASSETBUNDLE_EXT;
        //                 SetAssetBundleName(item, prefabName.ToLower());
        //             } else {
        //                 SetAssetBundleName(item, null);
        //             }
        //         }
        //     }
        // }
    }
    static void SetAssetBundleName(string path, string abName)
    {
        AssetImporter importer = AssetImporter.GetAtPath(path);
        if (abName != null) {
            if (importer.assetBundleName != abName) {
                importer.assetBundleName = abName;
            }
        } else {
            importer.assetBundleName = null;
        }
    }
}
